//
//  CookClassTableViewCell.m
//  Products_B
//
//  Created by lanou on 16/5/28.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "CookClassTableViewCell.h"
#define kFont [UIFont systemFontOfSize:14]
@interface CookClassTableViewCell() {
    
    UIImageView *_picImageViwew;
    UILabel *_titleLabel;
    UILabel *_updateLabel;
    UILabel *_persoNumberLable;
    UIImageView *_album_logoImageView;
    
}
@end

@implementation CookClassTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
  
        _picImageViwew = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kWidth * 662 / 1242)];
        [self.contentView addSubview:_picImageViwew];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, _picImageViwew.frame.origin.y + _picImageViwew.frame.size.height + 5, kWidth - 20, 30)];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_titleLabel];
        
        _updateLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 5, 120, 20)];
        _updateLabel.font = kFont;
        _updateLabel.alpha = 0.6;
        [self.contentView addSubview:_updateLabel];
        
        _persoNumberLable = [[UILabel alloc] initWithFrame:CGRectMake(150, _updateLabel.frame.origin.y, 200, 20)];
        _persoNumberLable.font = kFont;
        _persoNumberLable.alpha = 0.6;
        [self.contentView addSubview:_persoNumberLable];
        
        _album_logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth - 70, _picImageViwew.frame.origin.y + _picImageViwew.frame.size.height - 25, 50, 50)];
        _album_logoImageView.layer.cornerRadius = 25;
        _album_logoImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:_album_logoImageView];
    }
    return self;
}

// 重写set方法,将model的值传给cell上的子控件
- (void)setCookClassModel:(CookClassModel *)cookClassModel {
    _cookClassModel = cookClassModel;
    [_picImageViwew sd_setImageWithURL:[NSURL URLWithString:cookClassModel.image]];

    // 用#分割食课的标题,然后存放到数组中
   NSArray *arr = [cookClassModel.series_name componentsSeparatedByString:@"#"];
    // 取数组中最后一个元素作为食课的标题
    _titleLabel.text = arr.lastObject;
    _updateLabel.text = [NSString stringWithFormat:@"更新至第%ld集",cookClassModel.episode];
    _persoNumberLable.text = [NSString stringWithFormat:@"上课人数%ld",cookClassModel.play];
    [_album_logoImageView sd_setImageWithURL:[NSURL URLWithString:cookClassModel.album_logo]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
